Finalize "Multiple URL support" code.
authoroliskoli <oliskoli>
Mon, 12 Mar 2007 22:15:42 +0000 (22:15 +0000)
committeroliskoli <oliskoli>
Mon, 12 Mar 2007 22:15:42 +0000 (22:15 +0000)
cet_util.c
defs.h
gpx.c
waypt.c

index ad9b68f6fde6955f91a7c5aa9dc36a5d3088b9ba..5501a9139f1a061b36b6a69d250ce7c2c3600f64 100644 (file)
@@ -2,7 +2,7 @@
 
     Character encoding transformation - utilities
 
-    Copyright (C) 2005 Olaf Klein, o.b.klein@gpsbabel.org
+    Copyright (C) 2005,2006,2007 Olaf Klein, o.b.klein@gpsbabel.org
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -950,6 +950,7 @@ cet_convert_waypt(const waypoint *wpt)
 {
        waypoint *w = (waypoint *)wpt;
        format_specific_data *fs;
+       url_link *url_next;
        
        if ((cet_output == 0) && (w->wpt_flags.cet_converted != 0)) return;
        
@@ -960,6 +961,10 @@ cet_convert_waypt(const waypoint *wpt)
        w->notes = cet_convert_string(wpt->notes);
        w->url = cet_convert_string(wpt->url);
        w->url_link_text = cet_convert_string(wpt->url_link_text);
+       for (url_next = w->url_next; url_next; url_next = url_next->url_next) {
+               url_next->url = cet_convert_string(url_next->url);
+               url_next->url_link_text = cet_convert_string(url_next->url_link_text);
+       }
        
        fs = wpt->fs;
        while (fs != NULL)
diff --git a/defs.h b/defs.h
index 527c1b025633fa47d2823f05c758595f521de845..3ed825b43c068059dc9189d367c8e770e06a25e8 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -267,6 +267,15 @@ fs_xml *fs_xml_alloc( long type );
 #define FS_OZI 0x6f7a6900L
 #define FS_GMSD 0x474d5344L    /* GMSD = Garmin specific data */
 
+/*
+ * Structures and functions for multiple URLs per waypoint.
+ */
+typedef struct url_link {
+       struct url_link *url_next;
+       char *url;
+       char *url_link_text;
+} url_link;
+
 /*
  * Misc bitfields inside struct waypoint;
  */
@@ -409,25 +418,16 @@ typedef struct {
 typedef struct {
        double max_lat;
        double max_lon;
+       double max_alt;
        double min_lat;
        double min_lon;
+       double min_alt;
 } bounds;
 
 typedef struct {
        int request_terminate;
 } posn_status;
 
-/*
- * Structures and functions for multiple URLs per waypoint.
- */
-typedef struct url_link {
-       struct url_link *url_next;
-       char *url;
-       char *url_link_text;
-} url_link;
-
-void add_url(waypoint *wpt, char *link, char *url_link_text);
-
 
 
 typedef void (*ff_init) (char const *);
@@ -468,6 +468,7 @@ void waypt_flush(queue *);
 void waypt_flush_all(void);
 unsigned int waypt_count(void);
 void set_waypt_count(unsigned int nc);
+void waypt_add_url(waypoint *wpt, char *link, char *url_link_text);
 void free_gpx_extras (xml_tag * tag);
 void xcsv_setup_internal_style(const char *style_buf);
 void xcsv_read_internal_style(const char *style_buf);
diff --git a/gpx.c b/gpx.c
index cee3d927c43742cf11cbd84622b274360f94e5d3..70070d163a8fddbcff8278ef41e6798a7bfbfdd3 100644 (file)
--- a/gpx.c
+++ b/gpx.c
@@ -878,7 +878,7 @@ gpx_end(void *data, const XML_Char *xml_el)
                        lt = xstrdup(lrtrim(link_text));
                }
                
-               add_url(wpt_tmp, xstrdup(link_url), lt);
+               waypt_add_url(wpt_tmp, xstrdup(link_url), lt);
                link_text = NULL;
                }
                break;
diff --git a/waypt.c b/waypt.c
index da9b98fba8109b47b5c5de7df7b3b4233ec6226d..92a5ee464e698879b0338151b53b02d35385734a 100644 (file)
--- a/waypt.c
+++ b/waypt.c
@@ -41,6 +41,8 @@ waypt_dupe(const waypoint *wpt)
         * This and waypt_free should be closely synced.
         */
        waypoint * tmp;
+       url_link *url_next;
+
        tmp = waypt_new();
        memcpy(tmp, wpt, sizeof(waypoint));
 
@@ -54,6 +56,11 @@ waypt_dupe(const waypoint *wpt)
                tmp->url = xstrdup(wpt->url);
        if (wpt->url_link_text)
                tmp->url_link_text = xstrdup(wpt->url_link_text);
+       for (url_next = wpt->url_next; url_next; url_next = url_next->url_next) {
+               waypt_add_url(tmp,
+                       (url_next->url) ? xstrdup(url_next->url) : NULL,
+                       (url_next->url_link_text) ? xstrdup(url_next->url_link_text) : NULL);
+       }
        if (wpt->icon_descr && wpt->wpt_flags.icon_descr_is_dynamic)
                tmp->icon_descr = xstrdup(wpt->icon_descr);
        if (wpt->gc_data.desc_short.utfstring) {
@@ -222,6 +229,8 @@ waypt_init_bounds(bounds *bounds)
        bounds->max_lon = -9999;
        bounds->min_lat = 9999;
        bounds->min_lon = 9999;
+       bounds->max_alt = -unknown_alt;
+       bounds->min_alt = unknown_alt;
 }
 
 int
@@ -245,6 +254,12 @@ waypt_add_to_bounds(bounds *bounds, const waypoint *waypointp)
                bounds->min_lat = waypointp->latitude;
        if (waypointp->longitude < bounds->min_lon)
                bounds->min_lon = waypointp->longitude;
+       if (waypointp->altitude != unknown_alt) {
+               if (waypointp->altitude < bounds->min_alt)
+                       bounds->min_alt = waypointp->altitude;
+               if (waypointp->altitude > bounds->max_alt)
+                       bounds->max_alt = waypointp->altitude;
+       }
 }
 
 
@@ -399,3 +414,32 @@ waypt_restore(signed int count, queue *head_bak)
        waypt_ct = count;
        xfree(head_bak);
 }
+
+void
+waypt_add_url(waypoint *wpt, char *link, char *url_link_text)
+{
+       if ((link == NULL) && (url_link_text == NULL)) return;
+       
+       /* Special case first one; it goes right into the waypoint. */
+       if ((wpt->url == NULL)  && (wpt->url_link_text == NULL)) {
+               wpt->url = link;
+               wpt->url_link_text = url_link_text;
+       } else {
+               url_link *tail;
+               url_link *new_link = xcalloc(sizeof(url_link), 1);
+               new_link->url = link;
+               new_link->url_link_text = url_link_text;
+
+               /* Find current end of chain and tack this onto the end.. */
+               for (tail = wpt->url_next;;tail = tail->url_next) {
+                       if (tail == NULL) {
+                               wpt->url_next = new_link;
+                               break;
+                       }
+                       if (tail->url_next == NULL) {
+                               tail->url_next = new_link;
+                               break;
+                       }
+               }
+       }
+}